package com.hongpu.controller;

import com.hongpu.domain.SysUserRole;
import com.hongpu.dto.SysUserRoleDto;
import com.hongpu.service.SysUserRoleService;
import com.hongpu.utils.ResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张玉胜
 * @since 2025年06月04日
 */
@RestController
@RequestMapping("/sysUserRole")
public class SysUserRoleController {
    @Autowired
    private SysUserRoleService sysUserRoleService;
    /**
     * 一个用户设置一个角色
     */
    @PostMapping("/add")
    public ResultDto add(@RequestBody SysUserRole sysUserRole) {
        boolean result = sysUserRoleService.save(sysUserRole);
         if(!result){
             return ResultDto.fail();
         }
         return ResultDto.ok();
    }

    /**
     * 多个用户设置同一个角色
     * @param sysUserRoleDto
     * @return
     */
    @PostMapping("/multipleUsersSetTheSameRole")
    public ResultDto multipleUsersSetTheSameRole(@RequestBody SysUserRoleDto sysUserRoleDto) {
        return sysUserRoleService.multipleUsersSetTheSameRole(sysUserRoleDto);
    }

    /**
     * 根据用户ID和角色ID删除该用户的角色
     */
    @PostMapping("/deleteRoleByUserId")
    public ResultDto deleteRoleByUserId(@RequestBody SysUserRole sysUserRole) {
       return sysUserRoleService.deleteRoleByUserId(sysUserRole);
    }

    /**
     * 多个用户设置删除同一个角色
     * @param sysUserRoleDto
     * @return
     */
    @PostMapping("/multipleUsersDeleteTheSameRole")
    public ResultDto multipleUsersDeleteTheSameRole(@RequestBody SysUserRoleDto sysUserRoleDto) {
        return sysUserRoleService.multipleUsersDeleteTheSameRole(sysUserRoleDto);
    }

}